'''
zip函数将两个列表打包，进而创建字典

zip用法
zip([iterable,...])
'''
dict1 = dict()
dict1 = {}

dict1['firstname']='ma'
dict1['lastname']='yun'

dict1 = {'firstname':'ma','lastname':'yun'}
dict1 =dict([('firstname','ma'),('lastname','yun')] )
dict1 = dict(firstname='ma',lastname='yun')

dict1 = dict(zip(['firstname','ma'],['lastname','yun']))

#========方法1 两个列表创建字典
name_list = ['贾宝玉','林冲','猪八戒','赵子龙']
sign_list = ['红楼梦','水浒传','西游记','三国演义']

name_sign_dict = dict(zip(name_list,sign_list))

print(name_sign_dict)


#===============================
a = [1,2,3]
b = [4,5,6]
c = [4,5,6,7,8]
zipped = zip(a,b) #将两个列表打包为元组
print(list(zipped))

zipped = zip(a,c)
print(list(zipped)) #元素个数与最短的一致

zipped = zip(a,b)
unziped = zip(*zipped) # *zipped 可以理解为解压 返回二维矩阵
print(list(unziped))


#========方法二  通过键值对方式来创建字典

stu_dict= dict(a='11',b='22',c='33',d='44')
print(stu_dict)

#========方法三 创建只有键的字典
name_dict = dict.fromkeys(name_list)
print(name_dict)


#=====删除 字典
del name_dict
